package com.xmut.mall.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.xmut.mall.order.annotation.CheckJwt;
import com.xmut.mall.order.searchparam.AfterSaleReasonSearchParam;
import com.xmut.mall.order.utils.RespBean;
import com.xmut.mall.order.vo.PageVO;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.order.entity.AfterSaleReasonEntity;
import com.xmut.mall.order.service.AfterSaleReasonService;
import com.xmut.mall.order.utils.PageUtils;
import com.xmut.mall.order.utils.R;

@RestController
@RequestMapping("order/aftersalereason")
public class AfterSaleReasonController {
    @Autowired
    private AfterSaleReasonService afterSaleReasonService;



    /**
     * 根据售后类型获取官方设定的售后原因
     * @param type
     * @return
     */
    @CheckJwt
    @GetMapping("/getAfterSaleReasonByType/{type}")
    public RespBean getAfterSaleReasonByType(@PathVariable String type){
        return afterSaleReasonService.getAfterSaleReasonByType(type);
    }

    /**
     * 删除售后原因
     * @param id
     * @return
     */
    @CheckJwt
    @DeleteMapping("/deleteAfterSaleReason/{id}")
    public RespBean deleteAfterSaleReason(@PathVariable Long id){
        return afterSaleReasonService.deleteAfterSaleReason(id);
    }

    /**
     * 修改售后原因
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/updateAfterSaleReason")
    public RespBean updateAfterSaleReason(@RequestBody Map<String,Object> params){
        return afterSaleReasonService.updateAfterSaleReason(params);
    }

    /**
     * 添加售后原因
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/addAfterSaleReason")
    public RespBean addAfterSaleReason(@RequestBody Map<String,Object> params){
        return afterSaleReasonService.addAfterSaleReason(params);
    }

    /**
     * 获取售后原因分页数据
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getAfterSaleReasonByPage")
    public RespBean getAfterSaleReasonByPage(@RequestBody AfterSaleReasonSearchParam params){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(params,vo);
        return afterSaleReasonService.getAfterSaleReasonByPage(vo,params);
    }

}
